import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class fileUtile2 {
    private static void checkFilePath(String path) {
        if (path.trim().length() == 0 || path == null) {
            throw new IllegalArgumentException("路径不合法");
        }
    }

    private static void getFiles(String path, List<String> list) {
        checkFilePath(path);
        File file = new File(path);
        if (file.isDirectory()) {
            File[] files = file.listFiles();
            for (int i = 0; i < files.length; i++) {
                if (files[i].isDirectory()) {
                    getFiles(files[i].getPath(), list);
                } else {
                    list.add(files[i].getPath());
                }
            }
        } else {
            list.add(file.getPath());
        }
    }


    private static void getTheDirFiles(String path, List<String> list) {
        checkFilePath(path);
        File file = new File(path);
        if (file.isDirectory()) {
            File[] files = file.listFiles();
            for (int j = 0; j < files.length; j++) {
                list.add(files[j].getPath());
            }
        } else {
            list.add(file.getPath());
        }
    }


    private static void ChangeFilesName(String path) {
        checkFilePath(path);
        File file = new File(path);
        System.out.println(path);
        System.out.println(file.getParent().split("第")[1].split("天")[0]);
        System.out.println(s.split("-")[1].replace("_", " "));
        System.out.println(s);
        String cc=file.getParent().split("第")[1].split("天")[0];
        String name = file.getName();
        System.out.println("---------"+name.split("_")[1]);
    }

    public static void deleteAll(File file) {
        if (file.isDirectory())// 是文件夹
        {
            File[] files = file.listFiles();
            if (files.length > 0) {
                for (File file2 : files) {
                    deleteAll(file2);
                }
            }
            file.delete();

        } else {
            file.delete();
        }
    }

    public static void getIndexArrylist(List<String> list,List<String> youxulist){
        List<Integer> array = new ArrayList<Integer>();
        for (String string : list) {
            String a=string.split("_")[0].replace("E:\\新建文件夹\\java大数据\\", "");
            int mounth=Integer.parseInt(a.split("\\.")[0]);
            String regEx="[^0-9]";
            Pattern p = Pattern.compile(regEx);
            Matcher m = p.matcher(a.split("\\.")[1]);
            String number=m.replaceAll("").trim()+"";
            int days=Integer.parseInt(number);
            int c=mounth*30+days;
            array.add(c);
            Collections.sort(array);
        }
        for (Integer integer : array) {
            for (String string : list) {
                String a=string.split("_")[0].replace("E:\\新建文件夹\\java大数据\\", "");
                int mounth=Integer.parseInt(a.split("\\.")[0]);
                String regEx="[^0-9]";
                Pattern p = Pattern.compile(regEx);
                Matcher m = p.matcher(a.split("\\.")[1]);
                String number=m.replaceAll("").trim()+"";
                int days=Integer.parseInt(number);
                int c=mounth*30+days;
                if (c==integer) {
                    youxulist.add(string);
                }
            }
        }
        for (String string : youxulist) {
            System.out.println(string);
        }

    }

    private static void ChangeFilesNames(String path,int number) {
        try {

            checkFilePath(path);
            File file = new File(path);
            String name=file.getName();
            String a=name.split("_")[1];
            String c="E:\\新建文件夹\\第"+number+"天_"+a;
            File newfile=new File(c);
            file.renameTo(newfile);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static void main(String[] args) {
        List<String> list = new ArrayList<String>();
        getTheDirFiles("E:\\新建文件夹\\JS&JQuery", list);
        for (String string : list) {
            List<String> list1 = new ArrayList<String>();
            List<String> dlist2 = new ArrayList<String>();
            getTheDirFiles(string, dlist2);
            getFiles(string, list1);

            for (String string2 : list1) {
                ChangeFilesName(string2);
            }
        }
    }
}
